package com.github.niefy.modules.wx.controller;

import cn.hutool.core.thread.ThreadUtil;
import com.github.niefy.modules.wx.service.TemplateMsgService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import me.chanjar.weixin.mp.util.WxMpConfigStorageHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author yucl
 * @create 2021/5/26 13:54
 */
@RestController
@RequestMapping("/demo")
public class DemoController {
    @Autowired
    TemplateMsgService templateMsgService;

    @RequestMapping("/send/template/msg")
    public void sendTemplateMsg(){
        String appid = WxMpConfigStorageHolder.get();
        List<WxMpTemplateData> data  = new ArrayList<>();
        data.add(new WxMpTemplateData("first","郁才龙业务员"));
        data.add(new WxMpTemplateData("keyword1","换者名字，手机号。"));
        data.add(new WxMpTemplateData("keyword2","vap血脂"));
        data.add(new WxMpTemplateData("remark","，xxxx医院xxxx（患者姓名），130xxxxxx（手机号）的VAP血脂报告已出，请跟进，谢谢"));
        WxMpTemplateMessage wxMpTemplateMessage = WxMpTemplateMessage.builder()
                .templateId("MY_2HwiNGMEpiQ6bM4cdPmgSQiMvSMfv6QljsYFmbHg")
                .url("")
                .toUser("o_fngvlSpdHnsKql9K8dD7qKHgzI")
                .data(data)
                .build();
        ThreadUtil.execAsync(() -> {
            templateMsgService.sendTemplateMsg(wxMpTemplateMessage,"wx7eeac5736e7fb5ba1");
        });

        ThreadUtil.execAsync(() -> {
            templateMsgService.sendTemplateMsg(wxMpTemplateMessage,"wx7eeac5736e7fb5ba");
        });
    }
}
